package com.example.administrator.yuejian23.Activity;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.example.administrator.yuejian23.Bean.MyOrder;
import com.example.administrator.yuejian23.Const;
import com.example.administrator.yuejian23.R;
import com.example.administrator.yuejian23.Retrofit.RetrofitService;
import com.example.administrator.yuejian23.adapter.UserOrderAdapter;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator on 2017/10/27.
 */

public class MyOrderActivity extends Activity{
    private RecyclerView recyclerView;
    private Retrofit retrofit;
    private UserOrderAdapter userOrderAdapter;
    private List<MyOrder> myOrderList;
    private String User_Id;
    String id;
    private Context context;
    private int user_id;
    private String update_time;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        id="19";
     /*   context= MyOrderActivity.this;
        user_id = getApplication().getSharedPreferences("userInfo", Context.MODE_PRIVATE).getInt("user_id",0);*/
        setContentView(R.layout.activity_user_order);
        User_Id=getIntent().getStringExtra("User_Id");
        recyclerView= (RecyclerView) findViewById(R.id.user_order_recyclerview);
        retrofit=new Retrofit.Builder()
                .baseUrl(Const.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        RetrofitService services=retrofit.create(RetrofitService.class);
        retrofit2.Call<List<MyOrder>> call=services.getUserOrder(user_id);
        call.enqueue(new Callback<List<MyOrder>>() {
            @Override
            public void onResponse(Call<List<MyOrder>> call, Response<List<MyOrder>> response) {
                List<MyOrder> list=response.body();
                userOrderAdapter=new UserOrderAdapter(MyOrderActivity.this,list);
                LinearLayoutManager linearLayoutManager=new LinearLayoutManager(MyOrderActivity.this);
                linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                recyclerView.setLayoutManager(linearLayoutManager);
                recyclerView.setAdapter(userOrderAdapter);
                recyclerView.setItemAnimator(new DefaultItemAnimator());
            }

            @Override
            public void onFailure(Call<List<MyOrder>> call, Throwable t) {
                Toast.makeText(MyOrderActivity.this,"获取列表失败",Toast.LENGTH_SHORT).show();
            }
        });

    }
}

